package com.qqqq.web;

import com.alibaba.fastjson2.JSONObject;
import com.qqqq.core.AjaxResult;
import com.qqqq.core.BaseHttpServlet;
import com.qqqq.dao.impl.StudentDaoImpl;
import com.qqqq.domain.SignIn;
import com.qqqq.service.StudentService;
import com.qqqq.service.impl.StudentServiceImpl;
import com.qqqq.utils.ResponseUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;

@WebServlet("/sign")
public class AddSignServlet extends BaseHttpServlet {
    private StudentService studentService = new StudentServiceImpl(new StudentDaoImpl());

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        BufferedReader reader = req.getReader();
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line);
        }
        SignIn signIn = JSONObject.parseObject(sb.toString(), SignIn.class);
        executeBusiness(resp, response -> {
            ResponseUtils.responseJson(resp, AjaxResult.success(studentService.addStudentSign(signIn.getStuId())));
        });
    }
}
